home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / MultiSession 1.04 Source / Core 27⁄June⁄1993 / CButton.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-23  |  4.0 KB  |  172 lines  |  [TEXT/KAHL]

  1. /* CButton.c */
  2.  
  3. #include "CButton.h"
  4. #include "CWindow.h"
  5. #include "CEnclosure.h"
  6.  
  7.  
  8. #define MinTime (5) /* minimum time to hilite a button when pressed by key */
  9.  
  10.  
  11. /* initialize the button */
  12. void            CButton::IButton(LongPoint Start, LongPoint Extent, char Key, short Modifiers,
  13.                         CWindow* TheWindow, CEnclosure* TheEnclosure)
  14.     {
  15.         ERROR(Initialized == True,PRERR(ForceAbort,
  16.             "CButton::IButton called on already initialized object."));
  17.         EXECUTE(Initialized = True);
  18.         KeyEquivalent = Key;
  19.         KeyModifiers = Modifiers;
  20.         IViewRect(Start,Extent,TheWindow,TheEnclosure);
  21.     }
  22.  
  23.  
  24. /* process mouse down & do the stuff */
  25. void            CButton::DoMouseDown(MyEventRec Event)
  26.     {
  27.         MyBoolean        MouseInsideFlag;
  28.         MyBoolean        NeedToCallDoLeave;
  29.  
  30.         ERROR(Initialized != True,PRERR(ForceAbort,
  31.             "CButton::DoMouseDown called on uninitialized object."));
  32.         SetUpPort();
  33.         if (Enabled)
  34.             {
  35.                 MouseInsideFlag = True;
  36.                 DoEnter();
  37.                 NeedToCallDoLeave = True;
  38.                 RedrawHilited();
  39.                 ActiveModifiers = Event.Modifiers;
  40.                 while (WaitMouseUp())
  41.                     {
  42.                         if (LongPtInRect(MyGlobalToLocal(GetLongMouseLoc()),
  43.                             ZeroPoint,Extent) != MouseInsideFlag)
  44.                             {
  45.                                 MouseInsideFlag = !MouseInsideFlag;
  46.                                 if (MouseInsideFlag == True)
  47.                                     {
  48.                                         DoEnter();
  49.                                         NeedToCallDoLeave = True;
  50.                                         RedrawHilited();
  51.                                     }
  52.                                  else
  53.                                     {
  54.                                         DoLeave();
  55.                                         NeedToCallDoLeave = False;
  56.                                         RedrawNormal();
  57.                                     }
  58.                             }
  59.                         RelinquishCPU();
  60.                     }
  61.                 if (NeedToCallDoLeave)
  62.                     {
  63.                         DoLeave();
  64.                     }
  65.                 if (MouseInsideFlag)
  66.                     {
  67.                         if (!DoThang())
  68.                             {
  69.                                 /* if the button destroyed the window (i.e. a close button) */
  70.                                 /* it should return True */
  71.                                 RedrawNormal();
  72.                             }
  73.                     }
  74.             }
  75.     }
  76.  
  77.  
  78. MyBoolean    CButton::DoKeyDown(MyEventRec Event)
  79.     {
  80.         ERROR(Initialized != True,PRERR(ForceAbort,
  81.             "CButton::DoKeyDown called on uninitialized object."));
  82.         if (Enabled)
  83.             {
  84.                 if (((Event.Message & charCodeMask) == KeyEquivalent) && 
  85.                     ((Event.Modifiers & (cmdKey+shiftKey+optionKey)) == KeyModifiers))
  86.                     {
  87.                         long        TimeStarted;
  88.  
  89.                         TimeStarted = TickCount();
  90.                         RedrawHilited();
  91.                         if (!DoThang())
  92.                             {
  93.                                 /* if the button destroyed the window (i.e. a close button) */
  94.                                 /* it should return True */
  95.                                 while (TickCount() - TimeStarted < MinTime)
  96.                                     {
  97.                                         /* do nothing */
  98.                                     }
  99.                                 RedrawNormal();
  100.                             }
  101.                         return True;
  102.                     }
  103.             }
  104.         return False;
  105.     }
  106.  
  107.  
  108. /* draw the proper image (nothing, greyed out, or normal) */
  109. void            CButton::DoUpdate(void)
  110.     {
  111.         ERROR(Initialized != True,PRERR(ForceAbort,
  112.             "CButton::DoUpdate called on uninitialized object."));
  113.         RedrawNormal();
  114.     }
  115.  
  116.  
  117. void            CButton::DoEnable(void)
  118.     {
  119.         ERROR(Initialized != True,PRERR(ForceAbort,
  120.             "CButton::DoEnable called on uninitialized object."));
  121.         inherited::DoEnable();
  122.         SetUpPort();
  123.         Window->InvalidateLong(ZeroPoint,Extent);
  124.     }
  125.  
  126.  
  127. void            CButton::DoDisable(void)
  128.     {
  129.         ERROR(Initialized != True,PRERR(ForceAbort,
  130.             "CButton::DoDisable called on uninitialized object."));
  131.         inherited::DoDisable();
  132.         SetUpPort();
  133.         Window->InvalidateLong(ZeroPoint,Extent);
  134.     }
  135.  
  136.  
  137. void            CButton::RedrawHilited(void)
  138.     {
  139.         EXECUTE(PRERR(AllowResume,"CButton::RedrawHilited has not been overridden."));
  140.         ERROR(Initialized != True,PRERR(ForceAbort,
  141.             "CButton::RedrawHilited called on uninitialized object."));
  142.     }
  143.  
  144.  
  145. void            CButton::RedrawNormal(void)
  146.     {
  147.         EXECUTE(PRERR(AllowResume,"CButton::RedrawNormal has not been overridden."));
  148.         ERROR(Initialized != True,PRERR(ForceAbort,
  149.             "CButton::RedrawNormal called on uninitialized object."));
  150.     }
  151.  
  152.  
  153. /* override this to make the button do what you want it to */
  154. /* return True if the button deletes the window */
  155. MyBoolean    CButton::DoThang(void)
  156.     {
  157.         return False;
  158.     }
  159.  
  160.  
  161. /* DoEnter and DoLeave are called while the button is down as the user */
  162. /* moves over the button.  This can be used for "realtime" buttons such */
  163. /* as fast forward buttons */
  164. void            CButton::DoEnter(void)
  165.     {
  166.     }
  167.  
  168.  
  169. void            CButton::DoLeave(void)
  170.     {
  171.     }
  172.